﻿Imports KOR.Helpers

Public Module WebMsgBox

    Public ReadOnly Property Page As Page
        Get
            If TypeOf HttpContext.Current.Handler Is Page Then
                Return CType(HttpContext.Current.Handler, Page)
            Else
                Return Nothing
            End If
        End Get
    End Property

    Public Sub ShowError(ex As Exception, Optional showIntrusive As Boolean = True)
        If Not Page Is Nothing Then
            If showIntrusive Then
                ScriptManager.RegisterStartupScript(Page, GetType(Page), "WebMsgBox_Error1", "alert('" & ex.Message.FixJSString & "');", True)
            Else
                'show another kind of popup
            End If
        End If

    End Sub

    Public Sub ShowError(msg As String, Optional showIntrusive As Boolean = True)
        If Not Page Is Nothing Then
            If showIntrusive Then
                ScriptManager.RegisterStartupScript(Page, GetType(Page), "WebMsgBox_Error2", "alert('" & msg.FixJSString & "');", True)
            Else
                'show another kind of popup
            End If
        End If
    End Sub

    Public Sub ShowError(msg As String, ex As Exception, Optional showIntrusive As Boolean = True)
        If Not Page Is Nothing Then
            If showIntrusive Then
                ScriptManager.RegisterStartupScript(Page, GetType(Page), "WebMsgBox_Error3", "alert('" & (msg.ConcatCSV(". \n\n") & "Error Details: " & ex.ToString).FixJSString & ".');", True)
            Else
                'show another kind of popup
            End If
        End If
    End Sub

    Public Sub ShowWarning(msg As String, Optional showIntrusive As Boolean = False)
        If Not Page Is Nothing Then ScriptManager.RegisterStartupScript(Page, GetType(Page), "WebMsgBox_Warning", "alert('" & msg.FixJSString & "');", True)
    End Sub

    Public Sub ShowInfo(msg As String, Optional showIntrusive As Boolean = False)
        If Not Page Is Nothing Then ScriptManager.RegisterStartupScript(Page, GetType(Page), "WebMsgBox_Info", "alert('" & msg.FixJSString & "');", True)
    End Sub

    Public Sub ShowSuccess(msg As String, Optional mustShow As Boolean = False, Optional showIntrusive As Boolean = False)
        If Not Page Is Nothing Then
            If mustShow Then ScriptManager.RegisterStartupScript(Page, GetType(Page), "WebMsgBox_Success", "alert('" & msg.FixJSString & "');", True)
        End If
    End Sub

End Module

